home *** CD-ROM | disk | FTP | other *** search
- // 1. INCLUDES -----------------------------------------------------------
-
- #include <exec/exec.h>
- #include <intuition/intuition.h>
- #include <stdlib.h> /* EXIT_SUCCESS, EXIT_FAILURE */
-
- #include "saga.h"
-
- #define ANFS ANFRACSIZE
- #define BNFS (ANFRACSIZE-2)
-
- /* These are used for MeMask (1 << ID_xxx) */
- #define ID_BORDER 0
- #define ID_BNG 4
-
- #include "animtools.h"
- #include "gfx.h"
-
- // 2. DEFINES ------------------------------------------------------------
-
- // 3. EXPORTED VARIABLES -------------------------------------------------
-
- // 4. IMPORTED VARIABLES -------------------------------------------------
-
- IMPORT struct Window *HelpWindowPtr,
- *MainWindowPtr;
- IMPORT UWORD DisplayDepth;
-
- // 5. MODULE VARIABLES ---------------------------------------------------
-
- MODULE struct GelsInfo* gInfo;
- MODULE struct AnimOb *boingOb,
- *animKey;
-
- // 6. MODULE STRUCTURES --------------------------------------------------
-
- // 7. MODULE FUNCTIONS ---------------------------------------------------
-
- MODULE struct AnimOb* setupBoing(void);
- MODULE struct GelsInfo* setupDisplay(void);
- MODULE WORD goInFrontOfHead(struct AnimComp *aComp);
- MODULE WORD goBehindHead(struct AnimComp *aComp);
-
- // 8. CODE ---------------------------------------------------------------
-
- AGLOBAL void drawabout(void)
- { DrawImage(HelpWindowPtr->RPort, &About, 16 + 2, 20 + 2);
- }
- AGLOBAL void drawlogo(void)
- { DrawImage(MainWindowPtr->RPort, &Logo, (SCREENXPIXEL / 2) - (212 / 2), TBSIZE + 66);
- }
-
- MODULE struct GelsInfo* setupDisplay(void)
- { struct GelsInfo* gInfo;
-
- /* set up the gels system.
- ** 0x03 says: when you allocate sprites for me, don't ever use
- ** sprites zero or one. This guarantees that sprite zero, the
- ** intuition pointer, stays intact. Remember sprite one shares
- ** colors with sprite zero. */
-
- if (NULL != (gInfo = setupGelSys(HelpWindowPtr->RPort, 0x03)))
- { return(gInfo);
- } else
- { return(NULL);
- } }
-
- AGLOBAL VOID DrawGels(void)
- { Animate(&animKey, HelpWindowPtr->RPort);
- SortGList(HelpWindowPtr->RPort); /* Put the list in order. */
- DoCollision(HelpWindowPtr->RPort); /* Collision routines may called now */
- SortGList(HelpWindowPtr->RPort); /* Put the list in order. */
- DrawGList(HelpWindowPtr->RPort, ViewPortAddress(HelpWindowPtr));
- WaitTOF();
- }
-
- /*--------------------------------------------------------------
- ** setupBoing() - allocate and initialize an object that will
- ** display as a boing ball with orbiting satellites.
- **
- ** this is an animation object with four animation sequences
- ** (boing and three satellites). Note that the satellites all share the
- ** same single image data.
- **
- ** return NULL on failure.
- */
- MODULE struct AnimOb* setupBoing(void)
- { struct AnimOb* bngOb;
- struct AnimComp* bngComp;
- struct AnimComp* satAComp;
- struct AnimComp* satBComp;
- struct AnimComp* satCComp;
-
- /* Firstly, we allocate and initialize an AnimOb structure, then we */
- /* call makeSeq() for the main ball and for each satellite. */
-
- if (NULL != (bngOb = AllocMem((LONG)sizeof(struct AnimOb), MEMF_CLEAR)))
- { bngOb->NextOb = NULL;
- bngOb->PrevOb = NULL;
- bngOb->Clock = 0;
- bngOb->AnY = ( 28 << ANFRACSIZE);
- bngOb->AnX = ( 3 << ANFRACSIZE);
- bngOb->AnOldY = bngOb->AnY;
- bngOb->AnOldX = bngOb->AnX;
- bngOb->YVel = 0;
- bngOb->XVel = 1 << ANFRACSIZE;
- bngOb->YAccel = 0;
- bngOb->XAccel = 0;
- bngOb->RingYTrans = BNG3RINGY << ANFRACSIZE;
- bngOb->RingXTrans = BNG3RINGX << ANFRACSIZE;
- bngOb->AnimORoutine = bounceORoutine;
- bngOb->AUserExt = 0;
-
- newBoingBob.nb_DBuf = 0;
- newBoingBob.nb_RasDepth = DisplayDepth;
-
- newBoingSeq.nas_HeadOb = bngOb;
-
- satACRoutines[4] = goInFrontOfHead;
- satACRoutines[12] = goBehindHead;
- satBCRoutines[8] = goInFrontOfHead;
- satBCRoutines[0] = goBehindHead;
- satCCRoutines[4] = goInFrontOfHead;
- satCCRoutines[12] = goBehindHead;
-
- newSatABob.nb_DBuf = 0;
- newSatBBob.nb_DBuf = 0;
- newSatCBob.nb_DBuf = 0;
- newSatASeq.nas_HeadOb = bngOb;
- newSatBSeq.nas_HeadOb = bngOb;
- newSatCSeq.nas_HeadOb = bngOb;
-
- if (NULL != (bngComp = makeSeq(&newBoingBob, &newBoingSeq)))
- { bngComp->Flags |= RINGTRIGGER;
- bngOb->HeadComp = bngComp;
-
- if (NULL != (satAComp = makeSeq(&newSatABob, &newSatASeq)))
- { bngComp->AnimBob->Before = satAComp->AnimBob;
- satAComp->AnimBob->After = bngComp->AnimBob;
-
- if (NULL != (satBComp = makeSeq(&newSatBBob, &newSatBSeq)))
- { satAComp->AnimBob->Before = satBComp->AnimBob;
- satBComp->AnimBob->After = satAComp->AnimBob;
-
- if (NULL != (satCComp = makeSeq(&newSatCBob, &newSatCSeq)))
- { satBComp->AnimBob->Before = satCComp->AnimBob;
- satCComp->AnimBob->After = satBComp->AnimBob;
-
- bngComp->NextComp = satAComp;
- bngComp->PrevComp = NULL;
-
- satAComp->NextComp = satBComp;
- satAComp->PrevComp = bngComp;
-
- satBComp->NextComp = satCComp;
- satBComp->PrevComp = satAComp;
-
- satCComp->NextComp = NULL;
- satCComp->PrevComp = satBComp;
-
- return(bngOb);
- }
- freeSeq(satBComp, DEPTH);
- }
- freeSeq(satAComp, DEPTH);
- }
- freeSeq(bngComp, DEPTH);
- }
- FreeMem(bngOb, (LONG)sizeof(struct AnimOb));
- }
- return(NULL);
- }
-
- /*------------------------------------------------------
- ** This ORoutine makes the Object Bounce off Borders. */
-
- WORD bounceORoutine(struct AnimOb* anOb)
- { SHORT X = anOb->AnX >> ANFRACSIZE;
-
- if (((X < 3 ) && (anOb->XVel < 0)) ||
- ((X + (anOb->HeadComp->AnimBob->BobVSprite->Width << 4) > ABOUTXPIXEL - 3) && (anOb->XVel > 0)))
- { anOb->XVel = -(anOb->XVel);
- }
-
- return(0);
- }
-
- /*--------------------------------------------------------------
- ** This CRoutine rearranges Bob Before and After pointers in a
- ** way that makes the Component passed look like it is in front
- ** of its' head component.
- **
- ** Used for Boing satelittes.
- **
- ** So that they go in front of AND behind the boing ball.
- */
- MODULE WORD goInFrontOfHead(struct AnimComp *aComp)
- { /* close up hole */
- if (aComp->AnimBob->Before != NULL)
- aComp->AnimBob->Before->After = aComp->AnimBob->After;
- if (aComp->AnimBob->After != NULL)
- aComp->AnimBob->After->Before = aComp->AnimBob->Before;
-
- /* reinsert */
- aComp->AnimBob->Before = aComp->HeadOb->HeadComp->AnimBob->Before;
- aComp->AnimBob->After = aComp->HeadOb->HeadComp->AnimBob;
- if (aComp->AnimBob->Before != NULL)
- aComp->AnimBob->Before->After = aComp->AnimBob;
- aComp->HeadOb->HeadComp->AnimBob->Before = aComp->AnimBob;
-
- return(0);
- }
-
- /*--------------------------------------------------------------
- ** This CRoutine rearranges Bob Before and After pointers in a
- ** way that makes the Component passed look like it is behind
- ** its' head component.
- */
- MODULE WORD goBehindHead(struct AnimComp *aComp)
- { if (aComp->AnimBob->Before != NULL)
- aComp->AnimBob->Before->After = aComp->AnimBob->After;
- if (aComp->AnimBob->After != NULL)
- aComp->AnimBob->After->Before = aComp->AnimBob->Before;
-
- aComp->AnimBob->After = aComp->HeadOb->HeadComp->AnimBob->After;
- aComp->AnimBob->Before = aComp->HeadOb->HeadComp->AnimBob;
- if (aComp->AnimBob->After != NULL)
- aComp->AnimBob->After->Before = aComp->AnimBob;
- aComp->HeadOb->HeadComp->AnimBob->After = aComp->AnimBob;
-
- return(0);
- }
-
- AGLOBAL void boingball(void)
- { if (NULL != (gInfo = setupDisplay()))
- { InitAnimate(&animKey);
-
- if (NULL != (boingOb = setupBoing()))
- { AddAnimOb(boingOb, &animKey, HelpWindowPtr->RPort);
- } } }
-
- AGLOBAL void unboingball(void)
- { freeOb(boingOb, DEPTH);
- cleanupGelSys(gInfo, HelpWindowPtr->RPort);
- }
-
-